import 'package:enterprise_v6_app/app/core/http/http.dart';
import 'package:enterprise_v6_app/app/core/utils/interface.dart';
import 'package:enterprise_v6_app/app/core/utils/user_manager.dart';
import 'package:enterprise_v6_app/app/data/api/special_list.dart';
import 'package:enterprise_v6_app/app/data/entities/application/get_dict_all_entity.dart';

/// 获取字典所有数据
class DictDataInfo {
  // 特殊作业类型-树形结构
  static List<GetDictAllEntity> specialJobType = [];

  /// 根据字典type获取字典数据
  /// 根据字典列表id查询字典属性
  /// 不需要保存在内容的字典推荐使用该方法
  /// [dictionaryType] 字典值
  static Future<List<GetDictAllEntity>> getDictionaryDataByTree({required String dictionaryType, bool isTree = false}) async {
    // 未登录不执行操作
    if (!UserManager.isLoggedIn) {
      return [];
    }
    final res = await HttpUtil().generateGetRequest<List<GetDictAllEntity>>(
      enableCache: true,
      isTree ? Interface.getDictionaryDataByTree : Interface.getDetailsListByFanResponse,
      queryParameters: {'dictionaryType': dictionaryType},
    ).execute();
    List<GetDictAllEntity> dataList = [];
    res.onSuccess((result) {
      if (result.data != null) {
        dataList = result.data!;
      }
    });
    return dataList;
  }

  // 获取特殊作业类型字典
  static getTreeDictionaryDataByWorkType() async {
    // if (DictDataInfo.specialJobType.isNotEmpty) {
    //   return;
    // }
    final result = await SpecialListApis.getDictionaryDataByTree(dictionaryType: 'work_type').execute();
    result.onSuccess((value) {
      if (value.data != null) {
        DictDataInfo.specialJobType = value.data!;
      }
    });
  }
}
